<template>
  <el-dialog width="500px" title="分配权限" :visible.sync="isShow">
    <el-tree
      ref="tree"
      check-strictly
      show-checkbox
      :data="list"
      node-key="id"
      :default-checked-keys="defaultKeys"
      :props="{ label: 'name' }"
    />
    <template #footer>
      <div style="text-align: center">
        <el-button @click="cancelEvent">取消</el-button>
        <el-button type="primary" @click="submit">确认</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import { sysyPermission } from '@/api/permission'
import { changeData } from '@/utils/index.js'
import { sysRoleId, sysRoleAssignPrem } from '@/api/setting'
export default {
  data() {
    return {
      isShow: false,
      list: [],
      defaultKeys: [],
      id: ''
    }
  },
  created() {
    this.getData()
  },
  methods: {
    cancelEvent() {
      this.isShow = false
    },
    async getData() {
      const res = await sysyPermission()
      this.list = changeData(res.data, '0')
    },
    // 获取权限信息
    async getRoleInfo(id) {
      this.id = id
      const res = await sysRoleId(id)
      this.$refs.tree.setCheckedKeys(res.data.permIds)
      console.log('角色信息', res)
    },
    // 修改权限点
    async submit() {
      await sysRoleAssignPrem(this.id, this.$refs.tree.getCheckedKeys())
      this.$message.success('修改成功')
      this.cancelEvent()
    }
  }
}
</script>

<style></style>
